//package com.android;
//
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Color;
//import android.os.Bundle;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.FrameLayout;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.lzy.okgo.OkGo;
//import com.lzy.okgo.callback.StringCallback;
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//
//import okhttp3.Call;
//import okhttp3.Response;
//
///**
// * Created by TenFace on 17/10/25.
// * <p>    MACD、KDJ、RSI、DMI、DMA、WR、PSY、CR、ARBR、CCI、BIAS
// * 横屏
// */
//
//public class ChartActivity extends ChartBaseActivity {
//    private FrameLayout mChartLayout;
//    private TabScrollButton mScrollButton;
//    private String[] tabStrs = new String[]{"分时", "日K", "周K", "月K"};
//    private String[] typeStrs = new String[]{CommonType.TIME_TYPE_MIN, CommonType.TIME_TYPE_DAY, CommonType.TIME_TYPE_WEEK, CommonType.TIME_TYPE_MONTH};
//    private LinearLayout llHorizontalBack;
//    private TextView tvStockName, tvStockCode, tvStockPrice, tvStockPercent, tvStockVolume, tvLastTime;
//    private BaseChartView mBaseChartView = null;
//    private Bundle mBundle;
//    private String name;
//    public FrameLayout flChartTop;
//    private int tabIndex;
//    private Intent intent;
//    private String adjust = IndexModel.MAJUST;
//    private HqKlineDb hqKlineDb;
//    private QuoteStockInfoSnapData quoteStockInfoSnapData;
//
//    public static void startActivity(Context context, Bundle bundle) {
//        context.startActivity(new Intent(context, ChartActivity.class).putExtra("bundle", bundle));
//    }
//
//    @Override
//    protected int getContentView() {
//        return R.layout.activity_chart;
//    }
//
//    @Override
//    protected void initView() {
//        hqKlineDb = new HqKlineDb(getContext());
//        mChartLayout = (FrameLayout) findViewById(R.id.chart_layout);
//        mScrollButton = (TabScrollButton) findViewById(R.id.segment_button);
//        flChartTop = (FrameLayout) findViewById(R.id.flChartTop);
//        llHorizontalBack = (LinearLayout) findViewById(R.id.llHorizontalBack);
//        tvStockName = (TextView) findViewById(R.id.tvStockName);
//        tvStockCode = (TextView) findViewById(R.id.tvStockCode);
//        tvStockPrice = (TextView) findViewById(R.id.tvStockPrice);
//        tvStockPercent = (TextView) findViewById(R.id.tvStockPercent);
//        tvStockVolume = (TextView) findViewById(R.id.tvStockVolume);
//        tvLastTime = (TextView) findViewById(R.id.tvLastTime);
//
//        mScrollButton.maxbuttonCount = 0;
//        mScrollButton.setStrokeWidth(2);
//        mScrollButton.setStrokeColor(getResources().getColor(R.color.sk_main_text));
//        mScrollButton.setTextPressColor(getResources().getColor(R.color.sk_main_text));
//        mScrollButton.setContentStr(tabStrs);
//        mScrollButton.refresh();
//        intent = getIntent();
//        mBundle = intent.getBundleExtra("bundle");
//        tabIndex = mBundle.getInt("tabIndex");
//        name = mBundle.getString("name");
//
//        MobclickAgent.onEvent(ChartActivity.this, "pl_stock_lanscape");
//    }
//
//    @Override
//    protected void initData() {
////        getData();
//        String stockName = mBundle.getString("StockName");
//        String stockCode = mBundle.getString("StockCode");
//        String stockPrice = mBundle.getString("StockPrice");
//        String stockPercent = mBundle.getString("StockPercent");
//        String stockVolume = mBundle.getString("StockVolume");
//        String stockDate = mBundle.getString("StockDate");
//        int StockPercentColor = mBundle.getInt("StockPercentColor");
//
//        tvStockName.setText(stockName);
//        tvStockCode.setText("(" + stockCode + ")");
//
//        //格式化价格
//        tvStockPrice.setText(stockPrice);
//        tvStockPrice.setTextColor(StockPercentColor);
//        //涨跌幅
//        tvStockPercent.setText("(" + stockPercent + ")");
//        tvStockPercent.setTextColor(StockPercentColor);
//        //成交量
//        tvStockVolume.setText(stockVolume);
//        //交易时间
//        tvLastTime.setText(stockDate);
//    }
//
//    private void getData() {
//        //快照
//        OkGo.post(CommonURL.PUBLIC_SERVICE_QUOTE_LINE + CommonURL.QUOTE_REQUEST_STOCK_INFO_SNAP)
//                .upString("\"" + QuoteStockInfoActivity.stockCode + "\"")
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String s, Call call, Response response) {
//                        try {
//                            quoteStockInfoSnapData = JsonUtil.parseJsonToBean(s, QuoteStockInfoSnapData.class);
//                            String status = quoteStockInfoSnapData.getStatus();
//                            if (status != null) {
//                                if (status.equals(CommonType.STATUS_TYPE_SUCCESS)) {
//                                    tvStockName.setText(quoteStockInfoSnapData.getData().getName());
//                                    tvStockCode.setText("(" + quoteStockInfoSnapData.getData().getCode() + ")");
//
//                                    //格式化价格
////                                    String oldString = String.valueOf(quoteStockInfoSnapData.getData().getPrice());
//                                    tvStockPrice.setText(StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPrice()));
//
//                                    //成交量
//                                    tvStockVolume.setText(VolumeUtils.getVolUnit((float) quoteStockInfoSnapData.getData().getVolume()));
//                                    //交易时间
//                                    tvLastTime.setText(DateUtils.getDateToStringHm(DateUtils.getStringToDealTime(quoteStockInfoSnapData.getData().getDealtime())));
//
//                                    //红涨绿跌
//                                    if (quoteStockInfoSnapData.getData().getPercent() > 0) {
//                                        tvStockPercent.setText("(+" + StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPercent()) + "%)");
//                                        tvStockPercent.setTextColor(Color.argb(255, 255, 46, 91));//红
//                                        tvStockPrice.setTextColor(Color.argb(255, 255, 46, 91));//红
//                                    } else if (quoteStockInfoSnapData.getData().getPercent() < 0) {
//                                        tvStockPercent.setText("(" + StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPercent()) + "%)");
//                                        tvStockPercent.setTextColor(Color.argb(255, 52, 224, 144));//绿
//                                        tvStockPrice.setTextColor(Color.argb(255, 52, 224, 144));//绿
//                                    } else {
//                                        tvStockPercent.setText("(" + StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPercent()) + "%)");
//                                        tvStockPercent.setTextColor(Color.argb(255, 170, 170, 170));//灰色
//                                        tvStockPrice.setTextColor(Color.argb(255, 170, 170, 170));//灰色
//                                    }
//
//                                }
//                            }
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                    }
//
//                    @Override
//                    public void onError(Call call, Response response, Exception e) {
//                        super.onError(call, response, e);
//                    }
//                });
//
//
//    }
//
//    @Subscribe
//    public void onEventMainThread(BusUtils.BusSnapData busData) {
//
//        quoteStockInfoSnapData = busData.getData();//Snap的数据
//        if (!TextUtils.isEmpty(QuoteStockInfoActivity.stockCode)
//                && quoteStockInfoSnapData.getData().getCode().equals(QuoteStockInfoActivity.stockCode)) {
//            AppBaseNetWork.getInstance().isStockOpeningTime(new AppBaseNetWork.StateCallback() {
//                @Override
//                public void isSuccess(boolean isSuccess) {
//                    if (isSuccess) {
//                        String status = quoteStockInfoSnapData.getStatus();
//                        if (status != null) {
//                            if (status.equals(CommonType.STATUS_TYPE_SUCCESS)) {
//                                tvStockName.setText(quoteStockInfoSnapData.getData().getName());
//                                tvStockCode.setText("(" + quoteStockInfoSnapData.getData().getCode() + ")");
//
//                                //格式化价格
//                                tvStockPrice.setText(StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPrice()));
//
//                                //成交量
//                                tvStockVolume.setText(VolumeUtils.getVolUnit((float) quoteStockInfoSnapData.getData().getVolume()));
//                                //交易时间
//                                tvLastTime.setText(DateUtils.getDateToStringHm(DateUtils.getStringToDealTime(quoteStockInfoSnapData.getData().getDealtime())));
//
//                                //红涨绿跌
//                                String snapPercent = StringUtils.doubleToDoubleString(quoteStockInfoSnapData.getData().getPercent());
//                                if (quoteStockInfoSnapData.getData().getPercent() > 0) {
//                                    tvStockPercent.setText("(+" + snapPercent + "%)");
//                                    tvStockPercent.setTextColor(Color.argb(255, 255, 46, 91));//红
//                                    tvStockPrice.setTextColor(Color.argb(255, 255, 46, 91));//红
//                                } else if (quoteStockInfoSnapData.getData().getPercent() < 0) {
//                                    tvStockPercent.setText("(" + snapPercent + "%)");
//                                    tvStockPercent.setTextColor(Color.argb(255, 52, 224, 144));//绿
//                                    tvStockPrice.setTextColor(Color.argb(255, 52, 224, 144));//绿
//                                } else {
//                                    tvStockPercent.setText("(" + snapPercent + "%)");
//                                    tvStockPercent.setTextColor(Color.argb(255, 170, 170, 170));//灰色
//                                    tvStockPrice.setTextColor(Color.argb(255, 170, 170, 170));//灰色
//                                }
//
//                            }
//                        }
//                    }
//                }
//            });
//
//        }
//
//    }
//
//    @Override
//    protected void initListener() {
//        llHorizontalBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                intent.putExtra("tabIndex", tabIndex);
//                setResult(2, intent);
//                finish();
//
//            }
//        });
//
//        mScrollButton.setOnCheckedChangeListener(new TabScrollButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(int position, RelativeLayout button) {
//                if (mBaseChartView != null) {
//                    mBaseChartView.unRegister();
//                    mBaseChartView.destroy();
//                    mChartLayout.removeView(mBaseChartView);
//                    mBaseChartView.setActive(false);
//                }
//
//                tabIndex = position;
//                mBundle.putString("type", typeStrs[position]);
//                hqKlineDb.setTabIndex(position);
//                switch (position) {
//                    case 0:
//                        MobclickAgent.onEvent(ChartActivity.this, "btn_stock_realtime");
//                        EventBus.getDefault().post(new BusUtils.KLineRefreshStatus(false));
//                        mBaseChartView = new MinutesView(ChartActivity.this, flChartTop, mBundle);
//                        mBundle.putBoolean("fullScreen", true);
//                        MobclickAgent.onEvent(ChartActivity.this, "pl_stock_lanscape_realtime");
//                        mBaseChartView.setActive(true);
//                        break;
//                    case 1:
////                        mBundle.putBoolean("fullScreen", true);
////                        mBaseChartView = new FiveDayView(ChartActivity.this,flChartTop, mBundle);
////                        break;
//
//                        MobclickAgent.onEvent(ChartActivity.this, "btn_stock_day");
//                        EventBus.getDefault().post(new BusUtils.KLineRefreshStatus(true));
//                        mBundle.putBoolean("fullScreen", true);
//                        mBaseChartView = new KLineView(ChartActivity.this, flChartTop, mBundle, 0);
//                        MobclickAgent.onEvent(ChartActivity.this, "pl_stock_lanscape_day");
//                        break;
//                    case 2:
//
//                        MobclickAgent.onEvent(ChartActivity.this, "btn_stock_week");
//                        EventBus.getDefault().post(new BusUtils.KLineRefreshStatus(true));
//                        mBundle.putBoolean("fullScreen", true);
//                        mBaseChartView = new KLineView(ChartActivity.this, flChartTop, mBundle, 0);
//                        MobclickAgent.onEvent(ChartActivity.this, "pl_stock_lanscape_week");
//                        break;
//                    case 3:
//
//                        MobclickAgent.onEvent(ChartActivity.this, "btn_stock_month");
//                        EventBus.getDefault().post(new BusUtils.KLineRefreshStatus(true));
//                        mBundle.putBoolean("fullScreen", true);
//                        mBaseChartView = new KLineView(ChartActivity.this, flChartTop, mBundle, 0);
//                        MobclickAgent.onEvent(ChartActivity.this, "pl_stock_lanscape_month");
//                        break;
////                    case 4:
////                    case 5:
////                    case 6:
////                    case 7:
////                        EventBus.getDefault().post(new BusUtils.KLineRefreshStatus(true));
////                        mBundle.putBoolean("fullScreen", true);
////                        mBaseChartView = new KLineView(ChartActivity.this, flChartTop, mBundle, 0);
////                        break;
//
//                }
//                mChartLayout.addView(mBaseChartView);
//                mBaseChartView.start();
//                mBaseChartView.initData();
//            }
//        });
//
//        mScrollButton.perFormClick(tabIndex);
//
//
//    }
//
//
////    private CountDownTimer quoteStockInfoHorizontalTimer = new CountDownTimer(24 * 60 * 60 * 1000, 1000) {
////
////        @Override
////        public void onTick(long millisUntilFinished) {
////            try {
////                getData();
////            } catch (Exception e) {
////            }
////        }
////
////        @Override
////        public void onFinish() {
////        }
////    };
//
//    @Override
//    protected void onPause() {
//        super.onPause();
//        MobclickAgent.onPause(this);
////        quoteStockInfoHorizontalTimer.cancel();
//    }
//
//    @Override
//    protected void onResume() {
//        super.onResume();
//        MobclickAgent.onResume(this);
////        quoteStockInfoHorizontalTimer.start();
//    }
//
//    @Override
//    protected void onDestroy() {
////
////        try {
////            GalaxyMainActivity.userEditor.remove(CommonType.QUOTE_KLINE_DATA_DAY);
////            GalaxyMainActivity.userEditor.remove(CommonType.QUOTE_KLINE_DATA_WEEK);
////            GalaxyMainActivity.userEditor.remove(CommonType.QUOTE_KLINE_DATA_MONTH);
////            GalaxyMainActivity.userEditor.commit();
////        } catch (Exception e) {
////            e.printStackTrace();
////        }
//
//        if (mBaseChartView != null) {
//            mBaseChartView.unRegister();
//            mBaseChartView.destroy();
//            mChartLayout.removeView(mBaseChartView);
//            mBaseChartView.setActive(false);
//        }
//
////        if (quoteStockInfoHorizontalTimer != null) {
////            quoteStockInfoHorizontalTimer.cancel();
////        }
//        super.onDestroy();
//    }
//
//}
